﻿using System;
using System.Collections.Generic;

using System.Windows.Forms;
using System.Threading;

namespace Com
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ThreadExceptionHandler handler = new ThreadExceptionHandler();
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(handler.Application_ThreadException);
            Application.Run(new MainFrm());
        }
       
    }
    internal class ThreadExceptionHandler
    {
        public void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            try
            {
                if (this.ShowThreadExceptionDialog(e.Exception) == DialogResult.Abort){
                    Application.Exit();
                }
            }catch{
                try
                {
                    MessageBox.Show("严重错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }finally{
                    Application.Exit();
                }
            }
        }

        private DialogResult ShowThreadExceptionDialog(Exception ex)
        {
            SendErrInfo info = new SendErrInfo(string.Concat(new object[] { "错误信息：\n\n", ex.Message, "\n\n", ex.GetType(), "\n\nStack Trace:\n", ex.StackTrace }));
            return info.ShowDialog();
        }
    }
    public class SysConst
    {
        public static string DB_NAME = "DBNAME_JXXYCM";
    }
    public class SysLog
    {
        static string logfile = System.Environment.CurrentDirectory;
        public static void WriterFileOK(string msg)
        {
            string temp = DateTime.Now.Date.Year.ToString() + DateTime.Now.Date.Month.ToString() + DateTime.Now.Date.Day.ToString() + DateTime.Now.Date.Hour.ToString() + DateTime.Now.Date.Minute.ToString();
            string fileName = logfile + "\\" + temp + "_OK.txt";
            System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName, true, System.Text.Encoding.GetEncoding("gb2312"));
            try
            {
                sw.WriteLine(msg, 1, 4.2);
                sw.Flush();
            }
            finally
            {
                if (sw != null) sw.Close();
            }
        }
        public static void WriterFileError(string msg)
        {
            string temp = DateTime.Now.Date.Year.ToString() + DateTime.Now.Date.Month.ToString() + DateTime.Now.Date.Day.ToString() + DateTime.Now.Date.Hour.ToString() + DateTime.Now.Date.Minute.ToString();
            string fileName = logfile + "\\" + temp + "_Error.txt";
            System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName, true, System.Text.Encoding.GetEncoding("gb2312"));
            try
            {
                sw.WriteLine(msg, 1, 4.2);
                sw.Flush();
            }
            finally
            {
                if (sw != null) sw.Close();
            }

        }
    }
}
